// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next';
import { BeError, BeSuccess, ResponseDataType } from '@/utils/response';
import log from '@/utils/log';

export default function handler(req: NextApiRequest, res: NextApiResponse<ResponseDataType>) {
  // if (req.method?.toLowerCase() !== 'post') {
  //   res.status(200).json(BeError('不支持请求类型'));
  //   res.end();
  //   return;
  // }
  try {
    const data = {
      url: req.url,
      params: req.query,
      headers: req.headers,
      body: req.body,
    };
    log.info('请求类型', req.method?.toLowerCase(), '输出结果：', JSON.stringify(data));
    res.status(200).json(BeSuccess(data));
  } catch (err: any) {
    console.error(err);
    res.status(200).json(BeError(err));
  }
  res.end();
}
